<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<style type="text/css">
div#head_bg {
	width: 95%;
	height: 200;
	background-color: #C4E1FF;
	font-size: 13pt
}

div#body_bg {
	width: 95%;
	height: 200;
	background-color: #D0D8E8;
	font-size: 13pt
}

div#resultDiv {
	width: 95%;
	height: 200;
	background-color: #D0D8E8;
	font-size: 13pt
}

td.result_mangle{
width: 200px;
}
</style>

<script type="text/javascript">
resultArray = new Array();
</script>
<title><?php echo $title; ?></title>
</head>

<body>
	<div id='head_bg'>
		<div>
			<font size="4" color="#fff">上次登录时间：<?php echo $lastLoginTime; ?>
			</font>

		</div>
		<div>
			<font size="4" color="#fff">综合健康指数：<?php echo $totalScore; ?>
			</font>

		</div>
	</div>
	<div id='body_bg'>
		<div>
			<br /> <font size="4">已知症状：</font>
		</div>
		<div id='symp_panel'>
		<?php
		foreach($symptoms as $s)
		{
			echo '<div value="'.$s.'">';
			echo '<font size="4">'.$s.'</font>';
			echo '</div>';
		}
		if(count($symptoms) == 0)
		{
			echo '<div id="health_good"><font size="4">恭喜您, 您非常健康!</font></div>';	
		}
		?>
		</div>
	</div>
	<div id='head_bg'>
		<br /> <input id="startAnalyse" type="submit" value='开始新的基本健康分析'></input>
	</div>
	<br />
	<br />
	<div id='resultDiv' style="display: none">

		<center>
		<form>
			<table id="shared_info">
			<tr><td><center><h1>分析结果</h1></center></td></tr>
				<?php			
				function show_share_td($result, $exist, $shared, $index)
				{
					echo '<td>';
					echo '<label>'.$result."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>";
					echo "</td>";
					echo '<td class="result_mangle">';
					echo '<input type="checkbox" id="accept_chk'.$index.'" class="accept_chk" field="'.$result.'" '.( $exist ? "checked" : "").'>'."接受&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".'</input>';
					echo '</td>';
					echo '<td class="result_mangle">';
					echo '<input type="checkbox" id="share_chk'.$index.'" style="'.( $exist ? "display:block;" : "display:none;").'float:left" class="share_chk" field="'.$result.'" '.( $shared ? "checked" : "").'></input><label style="'.( $exist ? "display:block;" : "display:none;").'" id="share_label'.$index.'">分享&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>';
					echo '</td>';
				}

				for($i = 0; $i < count($analyseResult); $i++)
				{
					echo '<tr>';
					show_share_td($analyseResult[$i], $existSymptoms[$i], $sharedSymptoms[$i], $i);
					echo '</tr>';
				}
				
				if(count($analyseResult) == 0)
				{
					echo "<tr><td><center>恭喜您，您非常健康！</center></td></tr>";
				}
				?>
			</table>
		</form>
	</center>
	
	</div>

	<script language="javascript" type="text/javascript"
		src="<?php echo base_url()?>js/jquery1_8_0.js"></script>

	<script type="text/javascript">
        Array.prototype.indexOf = function(val) {
            for (var i = 0; i < this.length; i++) {
                if (this[i] == val) return i;
            }
            return -1;
        };
        Array.prototype.remove = function(val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };
                
    </script>

	<script type="text/javascript">

	function get_symptom_relation_map()
	{

/*		"总胆固醇临界：临界超标"=>1,
		"总胆固醇临界：超标"=>1,
		"低密度脂蛋白：临界超标"=>2,
		"低密度脂蛋白：超标"=>2,
		"甘油三酯：临界超标"=>3,
		"甘油三酯：超标"=>3,
		"血糖：临界糖尿病"=>4,
		"血糖：糖尿病"=>4,
		"血压：临界高血压"=>5,
		"血压：一阶高血压"=>5,
		"血压：二阶高血压"=>5,
		"消瘦"=>6,
		"超重"=>6,
		"肥胖"=>6,*/
		var map = new Array();
		map["总胆固醇临界：临界超标"] = 1;
		map["总胆固醇临界：超标"] = 1;
		map["低密度脂蛋白：临界超标"] = 2;
		map["低密度脂蛋白：超标"] = 2 ;
		map["甘油三酯：临界超标"] = 3;
		map["甘油三酯：超标"] = 3;
		map["血糖：临界糖尿病"] = 4;
		map["血糖：糖尿病"] = 4;
		map["血压：临界高血压"] = 5;
		map["血压：一阶高血压"] = 5;
		map["血压：二阶高血压"] = 5;
		map["消瘦"] = 6;
		map["超重"] = 6;
		map["肥胖"] = 6;

		return map;
	}

	function get_conflict_symptom(symptom_name)
	{
		var map = get_symptom_relation_map();
		var symptom_code = map[symptom_name];

		var result = new Array();

		for(var name in map)
		{
			if(symptom_name == name)
				continue;
			
			code = map[name];

			if(code == symptom_code)
				result.push(name);
		}

		return result;
	}
	
	$(
		function ()
		{
			$("input#reportData").click(
					function()
					{
						$("input#results").attr('value', resultArray.join());
					}
					);
			$("input#startAnalyse").click(
					function()
					{
						$("#resultDiv").css("display", "block");
						return false;
					}
					);
			$("input.share_chk").click(
					function()
					{
						field = $(this).attr("field");
						checked = this.checked;
						$.post("<?php echo site_url("personal_health_info_analyse/update_symptom_share");?>", 
								{
								    field: field,
								    checked: checked
						    	}
						);
					}
			);
			$("input.accept_chk").click(
					function()
					{
						field = $(this).attr("field");
						index = $(this).attr("id");
						
						index = index.substring(index.indexOf("accept_chk") + 10);
						checked = this.checked;
						if(checked)
						{
							$("#share_chk"+index).attr("checked", false);
							$("#share_chk"+index).css("display", "block");
							$("#share_label"+index).css("display", "block");							
						}
						else
						{
							$("#share_chk"+index).css("display", "none");
							$("#share_label"+index).css("display", "none");
						}
						
						$.post("<?php echo site_url("personal_health_info_analyse/update_symptom");?>", 
								{
								    field: field,
								    checked: checked
						    	},
						    	function(ret)
						    	{						    		
							    	var symptom_name = eval(ret);

							    	if(!checked)
							    	{	
  								    		
							    		$('div[value="'+symptom_name+'"]').remove();
							    		if($('#symp_panel').children().length == 0)
							    		{
							    			$('#symp_panel').append('<div id="health_good"><font size="4">恭喜您, 您非常健康!</font></div>');
								    	}
							    	}
							    	else
							    	{
								    	if($('#health_good').length > 0)
								    	{
								    		$('#health_good').remove();
								    	}

								    	var conflict_symptoms = get_conflict_symptom(symptom_name);
							    		for(var idx in conflict_symptoms)
							    		{
								    		var name = conflict_symptoms[idx];
							    			$('div[value="'+name+'"]').remove();
							    		}
								    	
								    	if($('div[value="'+symptom_name+'"]').length == 0)
								    	{
								    		$('#symp_panel').append('<div value="'+symptom_name+'"><font size="4">'+symptom_name+'</font></div>');
								    	}
								    }
					        	}
						);
					}
			);
		}
	);
	</script>

</body>
</html>
